import { login,getuserlist } from '../../http/https'
import { getToken, setToken, removeToken } from '../../utils/auth'

// 状态
const state = {
    token: getToken(),
    userInfo:{}
}
// 同步
const mutations = {
    // 设置token
  setToken(state, payload) {
    // 设置token
    state.token = payload // 此时认为payload就是传过来的token
    // 应该同步修改本地缓存的数据
    setToken(payload)
  },

  // 删除token
  removeToken(state) {
    state.token = null // 清除Vuex中的token
    removeToken() // 删除本地缓存的token
  },
}
// 异步
const actions = {
    async login(context, data) {
        let result = await login(data)
        context.commit('setToken', result.data)
    },
    async getuserlist(context) {
        let result = await getuserlist()
      console.log(36, result);
      return result
    }
}

export default {
    state,
    mutations,
    actions,
    namespaced: true
}